#include "UniversalDimensionConvertor.h"

void UniversalDimensionConvertor::projectiveToReal(float* data, float3* out, int x, int y, int size){
	setResolution(x, y);
	thrust::counting_iterator<int> index(0);
	float3 reset;
	reset.x = 0.0;
	reset.y = 0.0;
	reset.z = 0.0;

	thrust::fill(
		thrust::device_ptr<float3>(out),
		thrust::device_ptr<float3>(out) + size,
		reset
	);

	thrust::device_ptr<float> dev_ptr(data);
	
	thrust::transform(
		thrust::make_zip_iterator(thrust::make_tuple(dev_ptr, index)),
		thrust::make_zip_iterator(thrust::make_tuple(dev_ptr + size, index + size)),
		thrust::device_ptr<float3>(out), 
		univ_convert_ptr(x, y, fx, fy, cx, cy)
	);
}

void UniversalDimensionConvertor::projectiveToReal(float3* data, float3* out, int x, int y, int size){
	setResolution(x, y);

	thrust::transform(
		thrust::device_ptr<float3>(data),
		thrust::device_ptr<float3>(data) + size,
		thrust::device_ptr<float3>(out),
		univ_convert_ptr(x, y, fx, fy, cx, cy)
	);
}

void UniversalDimensionConvertor::realToProjective(float3* data, float* out, int x, int y){
	return;
}

void UniversalDimensionConvertor::realToProjective(float3* data, float* weight, float2* out, int x, int y){
	return;
}

//void UniversalDimensionConvertor::realToProjectiveHelper(float3* data, int x, int y){
//	setResolution(x, y);
//	thrust::transform(
//		thrust::device_ptr<float3>(data),
//		thrust::device_ptr<float3>(data) + x * y,
//		thrust::device_ptr<float3>(data),
//		univ_convert_rtp(x, y, fx, fy, cx, cy)
//	);
//}

void UniversalDimensionConvertor::realToProjective2(float3* data, float2* out, int x, int y, int size){
	thrust::transform(
		thrust::device_ptr<float3>(data),
		thrust::device_ptr<float3>(data) + size,
		thrust::device_ptr<float2>(out),
		univ_convert_rtp(fx, fy, cx, cy, x, y)
	);
}